package office.service.sale.impl;

import java.util.List;

import office.bo.sale.impl.CustomerProp;
import office.domainset.BizDomainProviderSetImpl;
import office.service.sale.ICustomerPropService;
import platform.common.dao.IDomainProvider;
import platform.common.dao.impl.DaoConfigException;
import platform.common.dao.impl.DaoException;
import platform.common.service.impl.BaseBizServiceImpl;

public class CustomerPropService  extends BaseBizServiceImpl implements ICustomerPropService {

	@SuppressWarnings("unchecked")
	public List<CustomerProp> getAllCustomerProp(){
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			IDomainProvider customerPropDP = domainProviderSetImpl.getCustomerPropDP();
			List<CustomerProp> list = (List<CustomerProp>)domainProviderSetImpl.getDao().findAllByDomian(customerPropDP);
			return list;
		} catch (DaoException e) {
			log.error("", e);
			return null;
		} catch (DaoConfigException e) {
			log.error("", e);
			return null;
		}
	}

	@Override
	public void saveCustomerProp(CustomerProp customerProp) {
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			domainProviderSetImpl.getDao().saveOrUpdate(customerProp);
		} catch (DaoException e) {
			log.error("", e);
		}  
	}

	@Override
	public CustomerProp getCustomerPropById(String id) {
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			IDomainProvider customerPropDP = domainProviderSetImpl.getCustomerPropDP();
			CustomerProp customerProp = (CustomerProp)domainProviderSetImpl.getDao().findByIdAndDomain(customerPropDP, id);
			return customerProp;
		} catch (DaoException e) {
			log.error("", e);
			return null;
		} catch (DaoConfigException e) {
			log.error("", e);
			return null;
		}
	}

	@Override
	public void deleteCustomerProp(String id) {
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			IDomainProvider customerPropDP = domainProviderSetImpl.getCustomerPropDP();
			domainProviderSetImpl.getDao().deleteById(customerPropDP, id);
		} catch (DaoException e) {
			log.error("", e);
		} catch (DaoConfigException e) {
			log.error("", e);
		}
		
	}
}
